<?php include('header.php'); ?>
<script type="text/javascript">
	window.onload = function()
	{
		$('.product').equalHeights();
	}
</script>
<div class="row">
	<div class="span4">
		
		<div class="row">
			<div class="span4" id="primary-img">
				<?php
				$photo	= theme_img('no_picture.png', lang('no_image_available'));
				$product->images	= array_values($product->images);

				if(!empty($product->images[0]))
				{
					$primary	= $product->images[0];
					foreach($product->images as $photo)
					{
						if(isset($photo->primary))
						{
							$primary	= $photo;
						}
					}

					$photo	= '<img class="responsiveImage" src="'.base_url('uploads/images/medium/'.$primary->filename).'" alt="'.$product->seo_title.'"/>';
				}
				echo $photo
				?>
			</div>
		</div>
		<?php if(!empty($primary->caption)):?>
		<div class="row">
			<div class="span4" id="product_caption">
				<?php echo $primary->caption;?>
			</div>
		</div>
		<?php endif;?>
		<?php if(count($product->images) > 1):?>
		<div class="row">
			<div class="span4 product-images">
				<?php foreach($product->images as $image):?>
				<img class="span1" onclick="$(this).squard('390', $('#primary-img'));" src="<?php echo base_url('uploads/images/medium/'.$image->filename);?>"/>
				<?php endforeach;?>
			</div>
		</div>
		<?php endif;?>

        <br/>
        <div class="row">
            <div class="span4">
                <div class="product-cart-form">
                    <?php echo form_open('cart/add_to_cart', 'class="form-horizontal"');?>
                    <input type="hidden" name="cartkey" value="<?php echo $this->session->flashdata('cartkey');?>" />
                    <input type="hidden" name="id" value="<?php echo $product->id?>"/>
                    <fieldset>
                        <?php if($product->quantity > 0):?>
                        <?php if(count($options) > 0): ?>
                        <?php foreach($options as $option):
                            $required	= '';
                            if($option->required)
                            {
                                $required = ' <p class="help-block">Required</p>';
                            }
                            ?>
                            <div class="control-group">
                                <div class="controls">
                                    <label class="controls-label"><?php echo $option->name;?></label>
                                    <?php
                                    /*
                                    this is where we generate the options and either use default values, or previously posted variables
                                    that we either returned for errors, or in some other releases of Go Cart the user may be editing
                                    and entry in their cart.
                                    */

                                    //if we're dealing with a textfield or text area, grab the option value and store it in value
                                    if($option->type == 'checklist')
                                    {
                                        $value	= array();
                                        if($posted_options && isset($posted_options[$option->id]))
                                        {
                                            $value	= $posted_options[$option->id];
                                        }
                                    }
                                    else
                                    {
                                        if(isset($option->values[0]))
                                        {
                                            $value	= $option->values[0]->value;
                                            if($posted_options && isset($posted_options[$option->id]))
                                            {
                                                $value	= $posted_options[$option->id];
                                            }
                                        }
                                        else
                                        {
                                            $value = false;
                                        }
                                    }

                                    if($option->type == 'textfield'):?>
                                        <div class="controls">
                                            <input type="text" name="option[<?php echo $option->id;?>]" value="<?php echo $value;?>" class="span2"/>
                                            <br/>
                                            <?php if ($option->required == 1) {echo lang('required');}?>
                                        </div>
                                        <?php elseif($option->type == 'textarea'):?>
                                        <div class="controls">
                                            <textarea class="span2" name="option[<?php echo $option->id;?>]"><?php echo $value;?></textarea>
                                            <br/>
                                            <?php if ($option->required == 1) {echo lang('required');}?>
                                        </div>
                                        <?php elseif($option->type == 'droplist'):?>
                                        <div class="controls">
                                            <select name="option[<?php echo $option->id;?>]" class="span2">
                                                <option value=""><?php echo lang('choose_option');?></option>

                                                <?php foreach ($option->values as $values):
                                                $selected	= '';
                                                if($value == $values->id)
                                                {
                                                    $selected	= ' selected="selected"';
                                                }?>

                                                <option<?php echo $selected;?> value="<?php echo $values->id;?>">
                                                    <?php echo($values->price != 0)?'('.format_currency($values->price).') ':''; echo $values->name;?>
                                                </option>

                                                <?php endforeach;?>
                                            </select>
                                            <br/>
                                            <?php if ($option->required == 1) {echo lang('required');}?>
                                        </div>
                                        <?php elseif($option->type == 'radiolist'):?>
                                        <div class="controls">
                                            <?php foreach ($option->values as $values):

                                            $checked = '';
                                            if($value == $values->id)
                                            {
                                                $checked = ' checked="checked"';
                                            }?>
                                            <label class="radio">
                                                <input<?php echo $checked;?> type="radio" name="option[<?php echo $option->id;?>]" value="<?php echo $values->id;?>"/>
                                                <?php echo $option->name;?> <?php echo($values->price != 0)?'('.format_currency($values->price).') ':''; echo $values->name;?>
                                            </label>
                                            <?php endforeach;?>
                                            <br/>
                                            <?php if ($option->required == 1) {echo lang('required');}?>
                                        </div>
                                        <?php elseif($option->type == 'checklist'):
                                        foreach ($option->values as $values):

                                            $checked = '';
                                            if(in_array($values->id, $value))
                                            {
                                                $checked = ' checked="checked"';
                                            }?>
                                            <label class="checkbox">
                                                <input<?php echo $checked;?> type="checkbox" name="option[<?php echo $option->id;?>][]" value="<?php echo $values->id;?>"/>
                                                <?php echo $values->name . ' '; echo($values->price != 0)?'('. lang('price').' '.format_currency($values->price).') ':''; ?>
                                            </label>
                                            <?php endforeach ?>
                                        <br/>
                                        <?php if ($option->required == 1) {echo lang('required');}?>
                                        <?php endif;?>
                                </div>    </div>
                            <?php endforeach;?>
                        <?php endif;?>
                            <div class="control-group">

                                <div class="controls">
                                    <?php if(!config_item('inventory_enabled') || config_item('allow_os_purchase') || !(bool)$product->track_stock || $product->quantity > 0) : ?>
                                        <label class="controls-label"><?php echo lang('quantity') ?></label>
                                        <br/>
                                        <?php if(!$product->fixed_quantity) : ?>
                                            <input oninvalid="this.setCustomValidity('<?php echo lang('quantity_error'); ?>')" class="span1" type="number" step="1" min="1" max=<?php echo $product->quantity; ?> name="quantity" value=""/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                    <?php endif; ?>

                                        <button class="btn btn-primary" type="submit" value="submit"><i class="icon-shopping-cart icon-white"></i> <?php echo lang('form_add_to_cart');?></button>
                                    <?php endif;?>
                                </div>
                            </div>
                        <?php else: ?>
                            <label class="controls-label"><?php echo lang('out_of_stock'); ?></label>
                        <?php endif;?>

                    </fieldset>
                    </form>
                </div>

            </div>
        </div>

        <br/>
        <?php if(!empty($product->related_products)):?>
        <div class="related_products">
            <div class="row">
                <div class="span4">
                    <h3 style="margin-top:20px;"><?php echo lang('related_products_title');?></h3>
                    <ul class="thumbnails">
                        <?php $count = 0; ?>
                        <?php foreach($product->related_products as $relate):

                            if ($this->Category_model->is_product_in_category($relate->id, $this->config->item('category_accessories'))){
                                continue;
                            }

                            if ($relate->enabled == 0){
                                //continue;
                            }
                        $count = $count + 1;
                        ?>
                        <li class="span2 product">
                            <?php
                            $photo	= theme_img('no_picture.png', lang('no_image_available'));

                            $relate->images	= array_values((array)json_decode($relate->images));

                            if(!empty($relate->images[0]))
                            {
                                $primary	= $relate->images[0];
                                foreach($relate->images as $photo)
                                {
                                    if(isset($photo->primary))
                                    {
                                        $primary	= $photo;
                                    }
                                }

                                $photo	= '<img src="'.base_url('uploads/images/thumbnails/'.$primary->filename).'" alt="'.$relate->seo_title.'"/>';
                            }
                            ?>
                            <a class="thumbnail" href="<?php echo site_url($relate->slug); ?>">
                                <?php echo $photo; ?>
                            </a>
                            <h5 style="margin-top:5px;"><a href="<?php echo site_url($relate->slug); ?>"><?php echo $relate->name;?></a></h5>

                            <div class="price_container">
                                <?php if($relate->saleprice > 0):?>
                                <span class="price_slash"><?php echo lang('product_reg');?> <?php echo format_currency($relate->price); ?></span><br/>
                                <span class="price_sale"><?php echo lang('product_sale');?> <?php echo format_currency($relate->saleprice); ?></span>
                                <?php else: ?>
                                <span class="price_reg"><?php echo lang('product_price');?><?php echo format_currency($relate->price); ?></span>
                                <?php endif; ?>
                            </div>
                            <?php if((bool)$relate->track_stock && $relate->quantity < 1 && config_item('inventory_enabled')) { ?>
                            <div class="stock_msg"><?php echo lang('out_of_stock');?></div>
                            <?php } ?>
                        </li>
                        <?php endforeach;?>
                    </ul>
                    <?php if($count == 0){
                        echo '<h5>'.lang('related_none').'</h5>';
                    }?>
                </div>
            </div>
        </div>
        <?php endif;?>

<!--        <div class="row" style="margin-top:15px; margin-bottom:15px;">-->
<!--            <div class="span4 sku-pricing">-->
<!--                --><?php //if(!empty($product->sku)):?><!--<div>--><?php //echo lang('sku');?><!--: --><?php //echo $product->sku; ?><!--</div>--><?php //endif;?><!--&nbsp;-->
<!--            </div>-->
<!--            --><?php //if((bool)$product->track_stock && $product->quantity < 1 && config_item('inventory_enabled')):?>
<!--            <div class="span4 out-of-stock">-->
<!--                <div>--><?php //echo lang('out_of_stock');?><!--</div>-->
<!--            </div>-->
<!--            --><?php //endif;?>
<!--        </div>-->

        <br/>
        <div class="row">
            <?php foreach($boxes as $box):?>
            <div class="span2">
                <div class="row">
                    <?php

                    $box_image	= '<img class="responsiveImage" src="'.base_url('uploads/'.$box->image).'" />';
                    if($box->link != '')
                    {
                        $target	= false;
                        if($box->new_window)
                        {
                            $target = 'target="_blank"';
                        }
                        echo '<a href="'.base_url().'index.php/'.$box->link.'" '.$target.' >'.$box_image.'</a>';
                    }
                    else
                    {
                        echo $box_image;
                    }
                    ?>
                </div>
<!--                <div class="row">-->
<!--                    <div class="control-group">-->
<!--                        <div class="controls">-->
<!--                            <br/>-->
<!--                            <label>--><?php //echo $box->title; ?><!--</label>-->
<!--                        </div>-->
<!--                    </div>-->
<!--                </div>-->
            </div>
                <br/>
            <?php endforeach;?>
        </div>
	</div>
	<div class="span8">
		
		<div class="row">
			<div class="span8">
				<div>
					<h2 style="font-weight:normal">
						<p style="border-bottom: 1px solid #dcdcdc;"><?php echo $product->name;?></p>
						<span class="pull-right">
                            <?php if($product->quantity <= 0):?>
                                <small><?php echo lang('out_of_stock');?></small>
                            <?php else: ?>
                                <?php if($product->saleprice > 0):?>
                                    <small><?php echo lang('on_sale');?></small>
                                    <span class="product_price"><?php echo format_currency($product->saleprice); ?></span>
                                <?php else: ?>
                                    <?php if($product->saleprice < 0):?>
                                        <small><?php echo lang('no_sale');?></small>
                                    <?php else: ?>
                                        <small><?php echo lang('on_sale');?></small>
                                        <span class="product_price"><?php echo format_currency($product->price); ?></span>
                                    <?php endif;?>
                                <?php endif;?>
                            <?php endif;?>
						</span>
					</h2>
				</div>
			</div>
		</div>
		
		<div class="row">
			<div class="span8">
				<?php echo $product->excerpt;?>
			</div>
		</div>

        <br/>
        <div class="row" style="margin-top:15px;">
			<div class="span8">
                <ul class="nav nav-pills" id="myTab">
                    <li class="active"><a href="#description" data-toggle="tab"><?php echo lang('description'); ?></a></li>
                    <li class=""><a href="#article" data-toggle="tab"><?php echo lang('article'); ?></a></li>
                    <li class=""><a href="#picture" data-toggle="tab"><?php echo lang('picture'); ?></a></li>
                    <li class=""><a href="#video" data-toggle="tab"><?php echo lang('video'); ?></a></li>
                    <?php if (!$this->Category_model->is_product_in_category($product->id, $this->config->item('category_accessories'))){

                        echo '<li class=""><a href="#accessory" data-toggle="tab">'.lang('accessory').'</a></li>';
                    } ?>
                </ul>

                <div class="tab-content">
                    <div class="tab-pane active" id="description">
                        <div id="">
                            <?php echo $product->description; ?>
                        </div>
                    </div>
                    <div class="tab-pane" id="article">
                        <div id="">

                        </div>
                    </div>
                    <div class="tab-pane" id="picture">
                        <div id="">

                        </div>
                    </div>
                    <div class="tab-pane" id="video">
                        <div id="">

                        </div>
                    </div>
                    <?php if (!$this->Category_model->is_product_in_category($product->id, $this->config->item('category_accessories'))){

                    echo '<div class="tab-pane" id="accessory">';
                    echo '<div id="">';
                    echo '<div class="row">';
                    echo '<div class="span8">';
                    echo '<ul class="thumbnails">';
                    $count = 0;
                    foreach($product->related_products as $relate):

                        if (!$this->Category_model->is_product_in_category($relate->id, $this->config->item('category_accessories'))){
                            continue;
                        }

                        if ($relate->enabled == 0){
                            //continue;
                        }
                        $count = $count + 1;
                        echo '<li class="span2 product">';

                        $photo	= theme_img('no_picture.png', lang('no_image_available'));

                        $relate->images	= array_values((array)json_decode($relate->images));

                        if(!empty($relate->images[0]))
                        {
                            $primary	= $relate->images[0];
                            foreach($relate->images as $photo)
                            {
                                if(isset($photo->primary))
                                {
                                    $primary	= $photo;
                                }
                            }

                            $photo	= '<img src="'.base_url('uploads/images/thumbnails/'.$primary->filename).'" alt="'.$relate->seo_title.'"/>';
                        }

                        echo '<a class="thumbnail" href="'.site_url($relate->slug).'">';
                        echo $photo;
                        echo '</a>';
                        echo '<h5 style="margin-top:5px;"><a href="'.site_url($relate->slug).'"">'.$relate->name.'</a></h5>';

                        echo '<div class="price_container">';
                        if($relate->saleprice > 0):
                            echo '<span class="price_slash">'.lang('product_reg').' '.format_currency($relate->price).'</span><br/>';
                            echo '<span class="price_sale">'.lang('product_sale').' '.format_currency($relate->saleprice).'</span>';
                        else:
                            echo '<span class="price_reg">'.lang('product_price').' '.format_currency($relate->price).'</span>';
                        endif;
                        echo '</div>';
                        if((bool)$relate->track_stock && $relate->quantity < 1 && config_item('inventory_enabled')) {
                            echo '<div class="stock_msg">'.lang('out_of_stock').'</div>';
                        }
                        echo '</li>';
                    endforeach;
                    echo '</ul>';

                    if($count == 0){
                        echo '<h5>'.lang('accessory_related_none').'</h5>';
                    }
                    echo '</div>';
                    echo '</div>';
                    echo '</div>';
                    echo '</div>';
                } ?>

                </div>

			</div>
		</div>
		
	</div>
</div>
<script type="text/javascript"><!--
$(function(){ 
	$('.category_container').each(function(){
		$(this).children().equalHeights();
	});	
});
//--></script>

<?php include('footer.php'); ?>